/**
 * Created by ZOE on 2017/5/10.
 */
(function() {
    $(function() {
        //初始化tab
        var loginType = CookieTool.get("xybsyw_login_type");
        if(loginType == 'SCHOOL'){
            $(".login_tab li").removeClass("on").eq(0).addClass("on");
            $("#userType").val("SCHOOL");
            $("#schoolForgetBar").show();
            $("#studentForgetBar,#enterpriseForgetBar").hide();
        }else if(loginType == "ENTERPRISE"){
            $(".login_tab li").removeClass("on").eq(2).addClass("on");
            $("#userType").val("ENTERPRISE");
            $("#enterpriseForgetBar").show();
            $("#schoolForgetBar,#studentForgetBar").hide();
        }else{
            $(".login_tab li").removeClass("on").eq(1).addClass("on");
            $("#userType").val("PSERON");
            $("#schoolForgetBar,#enterpriseForgetBar").hide();
            $("#studentForgetBar").show();
        }

        //隐藏系统提示的错误
        $("#username,#password").focus(function(){
            $(".login_error_t").hide();
        })
        $(".login_tab li").click(function() {
            $(this).addClass('on').siblings().removeClass('on');
            var userType = $(this).attr("data-value");
            $("#userType").val(userType);
            //学校企业隐藏注册，找回密码
            if($(this).attr("data-value")=="SCHOOL"){
                $("#schoolForgetBar").show();
                $("#studentForgetBar,#enterpriseForgetBar").hide();
            }else if($(this).attr("data-value")=="ENTERPRISE"){
                $("#enterpriseForgetBar").show();
                $("#schoolForgetBar,#studentForgetBar").hide();
            }else{
                $("#schoolForgetBar,#enterpriseForgetBar").hide();
                $("#studentForgetBar").show();
            }
        });
        //

        var loginURL = ctx + "/login.xhtml";

        //验证
        $("#loginForm").validate({
            submitHandler: function(form) {
                var loginType = $("#userType").val();
                CookieTool.add("xybsyw_login_type",loginType,"d7");
                form.submit();
            },
            errorPlacement: function(error, element) {
                error.appendTo(element.parent())
            },
            errorElement: "span",
            errorClass:"xyb_error",
            success: "valid",
            rules: {
                username: {
                    required: true,
                    minlength: 2

                },
                password: {
                    required: true,
                    minlength: 6
                }
            },
            messages: {
                username: {
                    required: "请输入您的用户名",
                    minlength: "请至少输入两个字符"

                },
                password: {
                    required: "请输入密码",
                    minlength: "密码不能小于{0}个字 符"
                }

            }
        });
    })

})();